package com.lagou.rpc.balance;

import com.lagou.rpc.netty.RpcClinetChannelHolder;

/**
 * @ClassName RpcLoadBanlance
 * @Description 负载均衡默认实现，轮训策略
 * @Author playboy
 * @Date 2021/6/5 4:43 下午
 * @Version 1.0
 **/
//@Component
public class DefaultRpcLoadBanlance extends AbstractRpcLoadBanlance {


	/**
	 * 轮训负载均衡获取channel，使用长链接
	 *
	 * @return
	 */
	@Override
	public RpcClinetChannelHolder getChannel() {
		RpcClinetChannelHolder rpcClinetChannelHolder = rpcClinetChannelHolders.get(index.getAndAdd(1) % rpcClinetChannelHolders.size());
		System.out.println("当前访问的地址：" + rpcClinetChannelHolder.getInetSocketAddress().getHostString() + ":" + rpcClinetChannelHolder.getInetSocketAddress().getPort());
		return rpcClinetChannelHolder;
	}

}
